#ifndef SCRIPT_MANAGER_H
#define SCRIPT_MANAGER_H

#include <QString>
#include <chrono>
#include <map>
#include <pybind11/embed.h>
#include <pybind11/stl.h>

namespace pybind11 {
class object;
class args;
} // namespace pybind11

class ScriptManager {
public:
  bool loadScript(const QString &objectId, const QString &scriptPath);
  bool unloadScript(const QString &objectId);
  bool reloadScript(const QString &objectId);
  pybind11::object
  executeFunction(const QString &objectId, const QString &functionName,
                  const pybind11::args &args = pybind11::tuple());
  pybind11::object getModule(const QString &objectId) const;
  bool isScriptLoaded(const QString &objectId) const;

private:
  std::map<QString, QString> m_scriptPaths;
  std::map<QString, pybind11::object> m_scriptModules;
  std::map<QString, std::chrono::system_clock::time_point> m_scriptLoadTimes;

  // 添加辅助方法
  bool loadScriptModule(const QString &objectId, const QString &scriptPath);
};

#endif // SCRIPT_MANAGER_H